<?php
class file_model extends CI_Model {
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'file' );
	}
	
	function get_type($file) {
		$output = exec ( "file $file" );
		$result = explode ( ": ", $output );
		return $result [1];
	}
	

	function read_file($file) {
		if ($this->is_text ( $file )) {
			return $this->highlight_code ( $file );
		} else {
			return '这不是文本文件!';
		}
	}


	function is_text($file) {
		$result = $this->get_type ( $file );
		if ($result == 'UTF-8 Unicode text' || $result == 'ASCII c program text') {
			return true;
		} else {
			return false;
		}
	}	
}

?>